package com.example.login.controller;

import com.example.login.entity.UserEntity;
import com.example.login.service.IUserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class UserController {

   @Autowired
   @Qualifier("userService")
   private IUserService userService;
    @PostMapping("/login")
    public @ResponseBody String Login(UserEntity userEntity, HttpSession session){
               String result=userService.login(userEntity);
               if (result.equals("success")){
                   session.setAttribute("userEntity",userEntity);
               }
        return result;
   }
   @GetMapping("/index")
    public String index(){
return "login/index";
   }
   @PostMapping("/register")
    public @ResponseBody String register(UserEntity userEntity){
        return userService.register(userEntity);
   }
}
